package cn.tinlan.shopcoin.app.mine.order;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.SectionEntity;

import java.util.List;

import cn.tinlan.shopcoin.R;
import cn.tinlan.shopcoin.app.car.adapter.ShopCarRVAdapter;
import cn.tinlan.shopcoin.app.car.model.ShopCarItemModel;
import cn.tinlan.shopcoin.widget.category.Constants;

/**
 * Created by Mortimer on 2018/11/27. 11:08
 * 佛祖🙏，永无bug。
 */
public class OrderAdapter extends BaseSectionQuickAdapter<OrderItemModel, BaseViewHolder> {
    private OrderAdapter.OnOrderHeadClickListener onmOrderHeadClickListener;
    public interface  OnOrderHeadClickListener {
        void onOrderHeadClick(View view, String shopid);
    }

    public void setOnmOrderHeadClickListener(OrderAdapter.OnOrderHeadClickListener onmOrderHeadClickListener) {
        this.onmOrderHeadClickListener = onmOrderHeadClickListener;
    }

    private Context mContext;
    private OrderItemModel orderItemModel;
    public OrderAdapter(Context context,int layoutResId, int sectionHeadResId, List<OrderItemModel> data) {
        super(layoutResId, sectionHeadResId, data);
        this.mContext = context;
    }
    @Override
    protected void convertHead(BaseViewHolder helper, final OrderItemModel item) {
        this.orderItemModel = item;

        helper.setText(R.id.order_head_title,item.header);

        String status = "";
        if (item.status.equals("1")){
            status = "待付款";
        } else if(item.status.equals("2")) {
            status = "待发货";
        } else if(item.status.equals("3")) {
            status = "待收货";
        } else if(item.status.equals("4")) {
            status = "待评价";
        } else if(item.status.equals("5")) {
            status = "已完成";
        }else {
            status = "订单异常";
        }

        helper.setText(R.id.order_head_status,status);
//        ImageView headImg = helper.getView(R.id.shopitem_head_selectimg);
//        headImg.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (onmOrderHeadClickListener != null){
//                    onmOrderHeadClickListener.onOrderHeadClick(v,item.shopid);
//                }
//            }
//        });
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderItemModel item) {
        OrderItemModel.OrderItemBean good = item.t;

        ImageView img = helper.getView(R.id.order_item_img);
        Glide.with(mContext).load(Constants.IMGURL+good.getThumb()).into(img);



        helper.setText(R.id.order_good_name, good.getName());

        helper.setText(R.id.order_good_price, "¥"+good.getPrice());
        helper.setText(R.id.order_good_num,"x"+good.getBuy_num());

        TextView allPrice = helper.getView(R.id.order_good_total);
        View     orderSub = helper.getView(R.id.order_good_sub);
        if (good.isIslastgood()) {
            allPrice.setVisibility(View.VISIBLE);
            orderSub.setVisibility(View.VISIBLE);
            allPrice.setText("共"+good.getAllNum()+"件商品  合计：  ¥"+good.getAllPrice());

            Button leftBtn = helper.getView(R.id.order_good_leftbtn);
            Button midBtn = helper.getView(R.id.order_good_midbtn);
            Button rightBtn = helper.getView(R.id.order_good_rightbtn);

            if (item.status.equals("1")){
                leftBtn.setVisibility(View.INVISIBLE);
                midBtn.setVisibility(View.INVISIBLE);
                rightBtn.setText("付款");
            } else if(item.status.equals("2")) {
                leftBtn.setVisibility(View.INVISIBLE);
                midBtn.setVisibility(View.INVISIBLE);
                rightBtn.setVisibility(View.INVISIBLE);
            } else if(item.status.equals("3")) {
                leftBtn.setVisibility(View.INVISIBLE);
                midBtn.setVisibility(View.INVISIBLE);
                rightBtn.setText("确认收货");
            } else if(item.status.equals("4")) {
                leftBtn.setVisibility(View.INVISIBLE);
                midBtn.setVisibility(View.INVISIBLE);
                rightBtn.setText("评价");
            } else if(item.status.equals("5")) {
                leftBtn.setVisibility(View.INVISIBLE);
                midBtn.setVisibility(View.INVISIBLE);
                rightBtn.setText("删除");
            }else {
                leftBtn.setVisibility(View.INVISIBLE);
                midBtn.setVisibility(View.INVISIBLE);
                rightBtn.setText("删除");
            }
        }else {
            allPrice.setVisibility(View.GONE);
            orderSub.setVisibility(View.GONE);
        }

//        if (t.isIslastgood()){
//            helper.setText(R.id.shopitem_price,"111111");
//            helper.getView(R.id.shopcar_bottom_img).setVisibility(View.VISIBLE);
//        }else {
//            helper.getView(R.id.shopcar_bottom_img).setVisibility(View.GONE);
//        }

    }
}
